Expand description
Some primitives to simplify implementation of structured data output in display mode. Usage example:
use core::fmt::{Display, Formatter, Result as FmtResult};
use cubob::display_struct;
struct Point {
x: i32,
y: i32,
}
struct Line {
a: Point,
b: Point,
}
impl Display for Point {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
display_struct(
f,
&[
(&"x", &self.x),
(&"y", &self.y),
],
)
}
}
impl Display for Line {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
display_struct(
f,
&[
(&"a", &self.a),
(&"b", &self.b),
],
)
}
}
let line = Line{ a: Point{ x: 0, y: 0}, b: Point{ x: 1, y: 1} };
println!("One-line: {}", line);
println!("Prettified: {:#}", line);
Structs
Field
field
Lets to output key-value pair regarding the propagated value of output alternativeness.
InstantList
list
and instant
Struct used to simplify displaying of any iterable lists.
InstantStruct
struct
and instant
Struct used to simplify displaying of any iterable maps.
ListShow
list
Lets to output some listed data regarding the propagated value of output alternativeness.
Passage(
list
or struct
) and instant
Source(
list
or struct
) and instant
StructShow
struct
Lets to output some structure regarding the propagated value of output alternativeness.
Enums
Alternate mode to use while outputting.
Traits
DisplayPair
struct
Trait used to generalize over tuples of displayable types
and references onto such tuples.
Trait is not sealed and can be implementd for any other needed type.
EmbedList
list
and embed
Trait letting to define embedding of implementing type list output into other type list output.
EmbedStruct
struct
and embed
Trait letting to define embedding of implementing type struct output into other type struct output.
Iterable(
list
or struct
) and instant
Trait used to generalize over IntoIterator+Copy and Iterator+Clone types.
Actual used source is defined via type parameter which should implement Kind trait.
There can be some problems when type implements Iterator and Copy simultaneously: since every Iterator
automatically implements IntoIterator, and Copy implementation requires Clone implementation too, such
type will suit both alternatives and will cause conflict until explicit Kind specified.
Trait is not sealed, so any user can define own Iterable implementation.
Kind(
list
or struct
) and instant
Special trait, generalizing all the types used to distinguish different types of iterable data sources.
Those types can be either type, implementing IntoIterator and Copy (so usual reference on IntoIterator suits)
or type, implementing Iterator and Clone.
There can be some problems when type implements Iterator and Copy simultaneously: since every Iterator
automatically implements IntoIterator, and Copy implementation requires Clone implementation too, such
type will suit both alternatives and will cause conflict until explicit Kind specified.
Trait is not sealed, so any user can define own kind and use it along with own Iterable implementation for that kind.
Functions
display_list
list
Performs the whole list output routine from creation of ListShow examplar to finishing.
Works with slice, always inherits alternate mode.
display_list_from_embed
list
and embed
Performs the whole list output routine from creation of ListShow examplar to finishing.
Works with iterator, always inherits alternate mode.
display_struct
struct
Performs the whole struct output routine from creation of StructShow examplar to finishing (for example see the crate-level documentation).
Works with slice, always inherits alternate mode.
display_struct_from_embed
struct
and embed
Routine to simplify Display implementation for type which already implements EmbedStruct.
display_struct_from_iter
struct
Performs the whole struct output routine from creation of StructShow examplar to finishing.
Works with iterator, always inherits alternate mode.